package tests.pl.shenlon.poker.cards.deck;

import junit.framework.Assert;

import org.junit.Test;

import pl.shenlon.poker.cards.CardRank;
import pl.shenlon.poker.cards.CardSuit;
import pl.shenlon.poker.cards.deck.Deck;
import pl.shenlon.poker.cards.deck.PokerDeck;

public class DeckTest {

	@Test
	public void testCardDealing() {
		Deck deck = new PokerDeck();
		deck.shuffle();
		while (deck.getCardsToDealCount() > 0) {
			Assert.assertNotNull(deck.next());
		}
	}

	@Test
	public void testForSize() {
		CardSuit[] suites = new CardSuit[] { CardSuit.CLUBS, CardSuit.DIAMONDS, };
		CardRank[] ranks = new CardRank[] { CardRank.ACE, CardRank.FIVE, };
		Deck deck = new Deck(suites, ranks);
		Assert.assertEquals(4, deck.getCardsInDeckCount());
		deck = new Deck(suites, CardRank.values());
		Assert.assertEquals(26, deck.getCardsInDeckCount());
		deck = new Deck(CardSuit.values(), CardRank.values());
		Assert.assertEquals(52, deck.getCardsInDeckCount());
		deck = new PokerDeck();
		Assert.assertEquals(52, deck.getCardsInDeckCount());
	}

	@Test
	public void testGetCardAtPosition() {
		Deck deck = new PokerDeck();
		for (int i = 0; i < deck.length; i++) {
			Assert.assertNotNull(deck.getCardAtPosition(i));
		}
	}

	@Test
	public void testGetCardAtPositionForShuffledDeck() {
		Deck deck = new PokerDeck();
		deck.shuffle();
		for (int i = 0; i < deck.length; i++) {
			Assert.assertNotNull(deck.getCardAtPosition(i));
		}
	}

	@Test
	public void testShuffle() {
		Deck deck = new PokerDeck();
		deck.shuffle();
		Assert.assertNotNull(deck.next());
		Assert.assertNotSame(deck.next(), deck.next());
	}

	@Test
	public void testShuffledDeckSize() {
		Deck deck = new PokerDeck();
		deck.shuffle();
		for (int i = 0; i < deck.getCardsInDeckCount(); i++) {
			Assert.assertNotNull(deck.next());
		}
	}
}